<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="货柜编码" prop="code">
        <el-input
          v-model="queryParams.code"
          placeholder="请输入货柜编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="锁头编码" prop="lockCode">
        <el-input
          v-model="queryParams.lockCode"
          placeholder="请输入锁头编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="货柜主人" prop="master">
        <el-input
          v-model="queryParams.master"
          placeholder="请输入货柜主人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="装柜日期" prop="loadingTime">
        <el-date-picker
          :editable="false"
          v-model="queryParams.loadingTime"
          type="date"
          value-format="yyyy-MM-dd"
          @keyup.enter.native="handleQuery"
          placeholder="请输入装柜日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="到港日期" prop="arrivalTime">
        <el-date-picker
          :editable="false"
          v-model="queryParams.arrivalTime"
          type="date"
          value-format="yyyy-MM-dd"
          @keyup.enter.native="handleQuery"
          placeholder="请输入到港日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:counter:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:counter:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:counter:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="counterList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="货柜编码" align="center" prop="code" fixed="left" min-width="130"/>
      <el-table-column label="锁头编码" align="center" prop="lockCode" min-width="130"/>
      <el-table-column label="货物体积" align="center" prop="cargoVolume" min-width="130"/>
      <el-table-column label="包装数量" align="center" prop="sumPackage" min-width="130"/>
      <el-table-column label="货柜负责人" align="center" prop="master" min-width="130"/>
      <el-table-column label="货柜负责人电话" align="center" prop="masterPhone" min-width="130"/>
      <el-table-column label="装柜日期" align="center" prop="loadingTime" min-width="150"/>
      <el-table-column label="到港日期" align="center" prop="arrivalTime" min-width="160"/>
      <el-table-column label="创建时间" align="center" prop="createTime" min-width="160"/>
      <el-table-column label="操作" align="center" width="180">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:counter:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:counter:remove']"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-s-goods"
            @click="goodsList(scope.row)"
            v-hasPermi="['system:counter:remove']"
          >货物</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { listCounter, delCounter} from "@/api/system/counter";

export default {
  name: "Counter",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 货柜表格数据
      counterList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        code: null,
        lockCode: null,
        master: null,
        masterPhone: null,
        loadingTime: null,
        arrivalTime: null,
        isDelete: null
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询货柜列表 */
    getList() {
      this.loading = true;
      listCounter(this.queryParams).then(response => {
        this.counterList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        code: null,
        lockCode: null,
        master: null,
        masterPhone: null,
        loadingTime: null,
        arrivalTime: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        isDelete: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$router.push("/warehouse/counter-save/index/0")
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$router.push("/warehouse/counter-save/index/" + row.id);
    },
    /** 货物列表 */
    goodsList(row) {
      this.$router.push("/warehouse/counter-goods/index/" + row.id)
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.loading = true;
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除货柜编号为"' + ids + '"的数据项？').then(function() {
        return delCounter(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/counter/export', {
        ...this.queryParams
      }, `counter_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
